package controller

import (
	"gitee.com/Frank098/devops-app-mgt/model"
	"gitee.com/Frank098/devops-app-mgt/service"
	"github.com/gin-gonic/gin"
)

var Pvc pvc

type pvc struct{}

// @Tags Pvc
// @Summary 获取pvc详情
// @Accept json
// @Produce json
// @Param pvc_name query string true "pvc名称"
// @Param namespace query string true "pvc命名空间"
// @Success 200 {object} model.Result ""
// @Failure 400 {object} model.Result""
// @Router /pvc/info [GET]
func (p *pvc) GetPvcInfo(ctx *gin.Context) {
	var params model.GetPvc
	if err := ctx.Bind(&params); err != nil {
		ErrorResponse(ctx, err, 400)
		return
	}
	data, err := service.Pvc.GetPvcInfo(params.PvcName, params.Namespace)
	if err != nil {
		ErrorResponse(ctx, err, 400)
		return
	}
	SuccessResponse(ctx, &model.Result{
		Code: 200,
		Msg:  "Success",
		Data: data,
	})
}

// @Tags Pvc
// @Summary 删除pvc
// @Accept json
// @Produce json
// @Param "" body model.GetPvc true "删除pvc"
// @Success 200 {object} model.Result ""
// @Failure 400 {object} model.Result""
// @Router /pvc/delete [DELETE]
// 删除pvc
func (p *pvc) DeletePvc(ctx *gin.Context) {
	var params model.GetPvc
	if err := ctx.ShouldBindJSON(&params); err != nil {
		ErrorResponse(ctx, err, 400)
		return
	}
	if err := service.Pvc.DeletePvc(params.PvcName, params.Namespace); err != nil {
		ErrorResponse(ctx, err, 400)
		return
	}
	SuccessResponse(ctx, &model.Result{
		Code: 200,
		Msg:  "Success",
		Data: "删除Pvc成功",
	})
}

/*
// 更新pvc
func (p *pvc) UpdatePvc(ctx *gin.Context) {
	params := new(struct {
		Namespace string `json:"namespace"`
		Content   string `json:"content"`
	})
	//PUT请求，绑定参数方法改为ctx.ShouldBindJSON
	if err := ctx.ShouldBindJSON(params); err != nil {
		logger.Error("Bind请求参数失败, " + err.Error())
		ctx.JSON(http.StatusInternalServerError, gin.H{
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}

	err := service.Pvc.UpdatePvc(params.Namespace, params.Content)
	if err != nil {
		ctx.JSON(http.StatusInternalServerError, gin.H{
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	ctx.JSON(http.StatusOK, gin.H{
		"msg":  "更新Pvc成功",
		"data": nil,
	})
}

*/
